# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=rebase
pkgver=4.4.1
pkgrel=6
pkgdesc="The Cygwin rebase distribution contains four utilities, rebase, rebaseall, peflags, and peflagsall."
groups=('base')
arch=('i686' 'x86_64')
license=('custom')
url="http://www.cygwin.com/"
depends=('msys2-runtime' 'dash')
makedepends=('coreutils' 'grep' 'gzip' 'sed')
# options=('debug' '!strip')
source=('rebase-4.4.1.tar.bz2'
        'rebase-4.4.1-msys2.patch'
        'autorebase.bat'
        'autorebasebase1st.bat'
        'rebaseall-add-python-exts.patch'
        'pacman-rec-filename-grep'
        'allow-non-database-mode-when-__CYGWIN__-__MSYS__.patch'
        'msys2-usr.patch')
sha1sums=('8f60d206e708b4ad77eb3223601637b5b3205021'
          '92866b5e2db0faa35dd6e04ec8140ba33d53f063'
          'e0410696a07a2aa2e71a90032e6613a6194ffa85'
          'f2ada0a753a8deef9901611ac5605613c8aafc59'
          '03f69430fba022ba968be7493705786d15ece79b'
          'a24eaaf73e92a604135ddf6169a4bcc4875b172a'
          '47efdc02e25611be06458d33098668a854f70d42'
          '23e296154eec725f6cddb989cc6e36c9bb70c336')

prepare() {
  cd "$srcdir/$pkgname-$pkgver"

  patch -p1 -i $srcdir/rebase-4.4.1-msys2.patch
  patch -p1 -i $srcdir/rebaseall-add-python-exts.patch
  patch -p1 -i $srcdir/allow-non-database-mode-when-__CYGWIN__-__MSYS__.patch
  patch -p1 -i $srcdir/msys2-usr.patch

  if check_option "strip" "n"; then
    sed -i "s/ -s//g" Makefile.in
  fi
  autoreconf -fi
}

build() {
  cd "$srcdir/$pkgname-$pkgver"

  ./configure --prefix=/usr \
    --sysconfdir=/etc \
    CXXFLAGS="${CXXFLAGS} -static -static-libgcc -static-libstdc++" \
    CFLAGS="${CFLAGS} -static -static-libgcc"
  make
}

package() {
  cd "$srcdir/$pkgname-$pkgver"

  make DESTDIR=${pkgdir} install
  cp -f ${srcdir}/autorebase.bat ${pkgdir}
  cp -f ${srcdir}/autorebasebase1st.bat ${pkgdir}
  cp -f ${srcdir}/pacman-rec-filename-grep ${pkgdir}/usr/bin
}
